package com.andy.base.mapper;

import com.andy.base.util.UrlSplitUtil;

import java.util.Map;

public class Context implements Mapper {

    Map<String,Wrapper> wrapperMap;

    public Context(Map<String, Wrapper> wrapperMap) {
        this.wrapperMap = wrapperMap;
    }

    /**
     * map到需要的对象,然后放入mappingData
     *
     * @param url
     * @param mappingData
     * @return
     * @throws Exception
     */
    @Override
    public Mapper map(String url, MappingData mappingData) throws Exception {
        String wrapperKey = UrlSplitUtil.getWrapper(url);
        Wrapper wrapper = wrapperMap.get(wrapperKey);

        mappingData.setWrapper(wrapper);
        mappingData.setWrapperKey(wrapperKey);

        return wrapper;
    }

    /**
     * 是否需要继续map
     *
     * @return
     */
    @Override
    public boolean needMapping() {
        return true;
    }
}
